/******************************************************************************
 * @file   :  item10.cpp
 * @brief  :  Be aware of allocator conventions and restrictions
 * Created :  09/11/2010 07:44:21 PM
 * Revision:  none
 * Compiler:  gcc -Wall -Wextra item10.cpp
 *
 * @author :  coanor, coanor@gmail.com
 ******************************************************************************/

 #include <list>

 using namespace std;

class widget {};

template<typename T>
class special_allocator {
	/*..*/
};

typedef special_allocator<widget> SAW;

int main()
{
	list<widget, SAW> L1;
	list<widget, SAW> L2;

	/* When list elements are spliced from one list to another, nothing is copyed.
	 * When L1 is destroyed, it must destroy all its nodes(and deallocate their
	 * memory), and because it now contains nodes that were originally part of L2.
	 * L1's allocator must deallocate the nodes that were originally allocated by
	 * L2's allocator.
	 *
	 * Now it should be clear that the Standard permits implementaters
	 * of the STL to assume that allocators of the same type are EQUIVALENT. It's
	 * so memory allocated by one allocator object(such as L2's) may be safely 
	 * deallocated by another allocator object(such as L1's).
	 */
	L1.splice(L1.begin(), L2); /* Move L2's node to the front of L1 */

	/*
	 *
	 */
	void * operator new(size_t bytes);
	pointer allocator<T>::allocate(size_type num_objects); /* Recall that "pointer" is a typedef 
	                                                          that's virtually always T* */

	return 0;
}
